﻿<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	<UsingTask TaskName="System.Workflow.ComponentModel.Compiler.CompileWorkflowTask" AssemblyName="System.Workflow.ComponentModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
	<UsingTask TaskName="System.Workflow.ComponentModel.Compiler.CreateWorkflowManifestResourceNameForCSharp" AssemblyName="System.Workflow.ComponentModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
	<PropertyGroup>
		<WinWFTempFiles>
		</WinWFTempFiles>
		<KeepWinWFTempFiles>
		</KeepWinWFTempFiles>
	</PropertyGroup>
	<PropertyGroup>
		<CoreCompileDependsOn>$(CoreCompileDependsOn);WorkflowCompilation</CoreCompileDependsOn>
		<CoreBuildDependsOn>$(CoreBuildDependsOn);WorkflowCompilationCleanup</CoreBuildDependsOn>
	</PropertyGroup>
	<!--Note: The inputs and outputs of the "WorkflowCompilation" target match those of 
              "Compile" target in CSharp.Targets/VisualBasic.Targets 
              except that "WorkflowCompilation" have @(Content) also as the input 
              because .Xoml files are represented as content items in the 
              project files.
              The inputs/outputs are evaluated at build time to determine if 
              the target's tasks need to be executed. -->

  <PropertyGroup>
    <CreateManifestResourceNamesDependsOn>
      $(CreateManifestResourceNamesDependsOn);PrepareWorkflowResources
    </CreateManifestResourceNamesDependsOn>
    <CreateCustomManifestResourceNamesDependsOn>
      $(CreateCustomManifestResourceNamesDependsOn);CreateWorkflowManifestResourceNames
    </CreateCustomManifestResourceNamesDependsOn>
    <CreateWorkflowManifestResourceNamesDependsOn></CreateWorkflowManifestResourceNamesDependsOn>
  </PropertyGroup>


  <Target Name="PrepareWorkflowResources"
          DependsOnTargets="$(CreateWorkflowManifestResourceNamesDependsOn)">

    <ItemGroup>
      <WFNonResxWithNoCulture Include="@(EmbeddedResource)"
        Condition="'%(EmbeddedResource.Extension)'=='.layout' and '%(EmbeddedResource.WithCulture)'=='false'"/>

      <WFNonResxWithNoCulture Include="@(EmbeddedResource)"
        Condition="'%(EmbeddedResource.Extension)'=='.rules' and '%(EmbeddedResource.WithCulture)'=='false'"/>

      <WFNonResxWithCulture Include="@(EmbeddedResource)"
        Condition="'%(EmbeddedResource.Extension)'=='.layout' and '%(EmbeddedResource.WithCulture)'=='true'"/>

      <WFNonResxWithCulture Include="@(EmbeddedResource)"
        Condition="'%(EmbeddedResource.Extension)'=='.rules' and '%(EmbeddedResource.WithCulture)'=='true'"/>
      <EmbeddedResource Remove="@(WFNonResxWithNoCulture)" />
      <EmbeddedResource Remove="@(WFNonResxWithCulture)" />
    </ItemGroup>

  </Target>
  <Target Name="CreateWorkflowManifestResourceNames"
          DependsOnTargets="$(CreateWorkflowManifestResourceNamesDependsOn)">

    <!-- Create WF specific resource names for non-culture non-resx files. -->

    <CreateWorkflowManifestResourceNameForCSharp  
      Condition="'@(WFNonResxWithNoCulture)'!=''"
      ResourceFiles="@(WFNonResxWithNoCulture)"
      RootNamespace="$(RootNamespace)">

      <Output TaskParameter="ResourceFilesWithManifestResourceNames" ItemName="EmbeddedResource"></Output>
    </CreateWorkflowManifestResourceNameForCSharp>

    <CreateWorkflowManifestResourceNameForCSharp  
      Condition="'@(WFNonResxWithCulture)'!=''"
      ResourceFiles="@(WFNonResxWithCulture)"
      RootNamespace="$(RootNamespace)">

      <Output TaskParameter="ResourceFilesWithManifestResourceNames" ItemName="EmbeddedResource"></Output>
    </CreateWorkflowManifestResourceNameForCSharp>

  </Target>

  <PropertyGroup>
    <WorkflowCompilationDependsOn>CreateWorkflowManifestResourceNames</WorkflowCompilationDependsOn>
  </PropertyGroup>

  <Target Name="WorkflowCompilation" 
	  Inputs="$(MSBuildAllProjects);
          @(Compile);
          @(Content);
          @(EmbeddedResource);
          $(ApplicationIcon);
          $(AssemblyOriginatorKeyFile);
          @(ManifestNonResxWithNoCultureOnDisk);
          @(ReferencePath);
          $(TargetFrameworkMoniker);
          @(CompiledLicenseFile)" 
          Outputs="$(DocFile);
          @(IntermediateAssembly); 
          $(NonExistentFile)"
    DependsOnTargets="$(WorkflowCompilationDependsOn)">

    <ItemGroup>      
      <WFCompilationResourcesWithNoCulture Include="@(EmbeddedResource)" 
        Condition="'%(EmbeddedResource.Type)'!='resx' and '%(EmbeddedResource.WithCulture)'=='false'"/>
      <WFCompilationResourcesWithNoCulture Include="$(IntermediateOutputPath)%(EmbeddedResource.ManifestResourceName).resources"
        Condition="'%(EmbeddedResource.Type)'=='resx' and '%(EmbeddedResource.WithCulture)'=='false'"/>

      <WFCompilationResourcesWithUnknownCulture Include="@(EmbeddedResource)"
        Condition="'%(EmbeddedResource.Type)'!='resx' and '%(EmbeddedResource.WithCulture)'==''"/>
      <WFCompilationResourcesWithUnknownCulture Include="$(IntermediateOutputPath)%(EmbeddedResource.ManifestResourceName).resources"
        Condition="'%(EmbeddedResource.Type)'=='resx' and '%(EmbeddedResource.WithCulture)'==''"/>
      <WFCompilationResourcesWithNoCulture Include="@(WFCompilationResourcesWithUnknownCulture)"
        Condition="'@(WFCompilationResourcesWithNoCulture)'=='' and '@(WFCompilationResourcesWithUnknownCulture)'!=''"/>
    </ItemGroup>

    <ItemGroup>
       <WFCompilationOptions Include="define" Condition="'$(DefineConstants)' != ''">
          <value>$(DefineConstants)</value>
          <delimiter>:</delimiter>
       </WFCompilationOptions>
       <WFCompilationOptions Include="nowarn" Condition="'$(NoWarn)' != ''">
          <value>$(NoWarn)</value>
          <delimiter>:</delimiter>
       </WFCompilationOptions>
    </ItemGroup>      

    <CompileWorkflowTask 
      Imports="@(Import)"
      RootNamespace="$(RootNamespace)" 
      AssemblyName="$(AssemblyName)"
      ProjectDirectory="$(MSBuildProjectDirectory)" 
      ProjectExtension="$(MSBuildProjectExtension)" 
      ResourceFiles="@(WFCompilationResourcesWithNoCulture);@(CompiledLicenseFile)"
      ReferenceFiles="@(ReferencePath)" 
      SourceCodeFiles="@(Compile)" 
      WorkflowMarkupFiles="@(Content)"
      CompilationOptions="@(WFCompilationOptions)"
      DelaySign="$(DelaySign)"
      TargetFramework="$(TargetFrameworkMoniker)"
      KeyContainer="$(KeyContainerName)"
      KeyFile="$(KeyOriginatorFile)"
	  BuildingProject="$(BuildingProject)">
      <Output TaskParameter="OutputFiles" ItemName="Compile" />
      <Output TaskParameter="TemporaryFiles" ItemName="WinWFTempFiles" />
      <Output TaskParameter="KeepTemporaryFiles" ItemName="KeepWinWFTempFiles" />
    </CompileWorkflowTask>
  </Target>

  <Target Name="WorkflowCompilationCleanup" Condition="'@(KeepWinWFTempFiles)'=='False'">
    <Delete 
	Files="@(WinWFTempFiles)" 
	Condition="'@(WinWFTempFiles)' != ''" />
  </Target>
</Project>